package com.example.demo.web;

import com.example.demo.config.properties.Project;
import com.example.demo.mybatis.mapper.CoreUserMapper;
import com.example.demo.mybatis.model.CoreUser;
import com.example.demo.service.UserServices;
import com.example.demo.web.base.ErrorMap;
import com.example.demo.web.base.JsonRetException;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by xiabin on 2017/7/14.
 */
@Controller
public class IndexController {
    @Autowired
    Project projectProperty;
    @Autowired
    CoreUserMapper coreUserMapper;

    @ApiOperation(value="SimpleTest", notes="测试Helloworld")
    @RequestMapping("/")
    @ResponseBody
    List<CoreUser> Index() {
        PageHelper.startPage(1, 10);
        List<CoreUser> userList = coreUserMapper.selectAll();
        return userList;
        /*return "Spring Boot L1" + "made by" + projectProperty.getAuthor() + "use" + projectProperty.getType();*/
    }

    @RequestMapping("/h5")
    String H5Index(Model model) {
        model.addAttribute("host", "http://vv-tech.com");
        return "index";
    }

    @RequestMapping("/hello")
    String ErrorTest() throws Exception {
        throw new Exception("发生错误");
    }

    @RequestMapping("/jsonErr")
    String JsonErrorTest() throws Exception {
        throw new JsonRetException(ErrorMap.SysErr);
    }
}
